<template>
  <div>
    <el-table
      ref="table"
      :key="tableKey"
      v-loading="listLoading"
      :header-cell-style="{background:'#F5F4F7'}"
      :data="list"
      border
      fit
      stripe
      highlight-current-row
      :height="tableHeight"
      style="width: 100%;"
    >
      <el-table-column
        type="index"
        width="60"
        label="编号"
        prop="id"
      />
      <!-- <el-table-column label="单据模板名称" width="220">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="流程名称" width="220">
        <template slot-scope="scope">
          <span>{{ scope.row.resourceName.split('.')[0] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="描述" min-width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.description }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发布版本" width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.version }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="资源名称" min-width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.resourceName }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column fixed="right" align="center" label="启用/停用" width="100">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.blnisinactive"
            active-color="#3FBEB8"
            inactive-color="#B7B7B7"
            :active-value="0"
            :inactive-value="1"
            @change="changeState($event,scope.row)"
          />
        </template>
      </el-table-column> -->
      <el-table-column align="center" label="操作" width="120" class-name="mb0">
        <template slot-scope="{row}">
          <el-button type="text" @click="visio(row)">流程图</el-button>
          <el-button type="text" class="del" @click="handleModifyStatus(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      v-if="paging.total > 0"
      background
      :current-page.sync="paging.page"
      :page-sizes="[10, 20, 30, 40]"
      :page-size.sync="paging.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="paging.total"
      @size-change="queryListByPage('search')"
      @current-change="queryListByPage"
    />
    <Visio ref="Visio" />
  </div>
</template>
<script>
import { queryList, del, changeState } from '@/api/system/approval-flow/approval-type'
import calculateCommonTableHeight from '@/layout/mixin/calculateCommonTableHeight'
export default {
  name: 'TableArea',
  components: {
    Visio: () => import('./Visio')
  },
  mixins: [calculateCommonTableHeight],
  data() {
    return {
      list: [],
      tableKey: 0,
      listLoading: false,
      paging: {
        total: 0,
        page: 1,
        size: 10
      },
      formInline: {
        name: '',
        lngworkflowtemplateid: ''
      }
    }
  },
  created() {
    console.log(1111)
    this.queryListByPage()
  },
  methods: {
    queryListByPage(str = '') {
      if (str === 'search') {
        this.paging.page = 1
      }
      queryList(
        this.formInline,
        this.paging.page,
        this.paging.size
      ).then(res => {
        if (res.code === 0) {
          this.paging.total = res.count
          this.list = res.data
        }
      })
    },
    // 删除
    handleModifyStatus(row) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        del(row.deploymentId).then(res => {
          if (res.flag === true) {
            this.$message({
              showClose: true,
              message: '删除成功',
              type: 'success'
            })
            this.queryListByPage()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 编辑
    handleUpdate(row) {
      this.$emit('edit', row)
    },
    // 流程图
    visio(row) {
      console.log(row)
      this.$refs.Visio.show()
      this.$refs.Visio.getImages(row)
    },
    changeState(e, row) {
      this.$confirm(e === 1 ? '确定要停用吗？' : '确定要启用吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        changeState(row).then(res => {
          if (res.code === 20000) {
            this.$message.success(res.message)
          }
        }).catch(() => {
          row.blnisinactive = e === 1 ? 0 : 1
        })
      }).catch(() => {
        row.blnisinactive = e === 1 ? 0 : 1
      })
    }
  }
}
</script>

